<!--
 * @Author: 汪军 624473119@qq.com
 * @Date: 2023-10-10 18:15:53
 * @LastEditors: 汪军 624473119@qq.com
 * @LastEditTime: 2023-12-12 09:32:39
 * @FilePath: \ekee-web\src\views\end\easy-link\EasyLink.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template lang="pug">
.my-fans.relative.h100
  div.container.overflow-y
    EnterpriseCenterTitle(:titleList="titleList")
    .mt4.px4(v-if="attentionList.length > 0")
      div(v-for="(item, index) in attentionList", :key="index")
        FanList(:item="item", @change="onAttention")
    Empty(v-else)
  //- 分页
  TablePagination(
    v-if="totalList > 0",
    :totalList="totalList",
    :page="fanindexPage.page",
    @handleCurrentChange="handleCurrentChange")
</template>

<script setup>
import { ref, getCurrentInstance, onMounted } from "vue";
import FanList from "@/components/fanList.vue";
import TablePagination from "@/components/TablePagination.vue";
import Empty from "@/components/Empty.vue";

import { FanIndex, FanCreate, FanDelete } from "@/api/barterhall";
const { proxy } = getCurrentInstance();

onMounted(() => {
  getFanIndex();
});
const titleList = ref([
  {
    name: "粉丝",
    value: 0,
  },
]);
//数据总条数
const totalList = ref(0);
const fanindexPage = ref({
  page: 1,
  page_size: 10,
});
const getFanIndex = () => {
  FanIndex(fanindexPage.value).then((res) => {
    if (res.code == 1) {
      attentionList.value = res.data.data;
      totalList.value = res.data.total; //总条数
      titleList.value[0].value = res.data.total;
    }
  });
};
const attentionList = ref([]);

const handleCurrentChange = (val) => {
  fanindexPage.value.page = val;
  getFanIndex();
};

// 回关
const onAttention = (item) => {
  console.log("item", item.each);
  if (item.each == 0) {
    FanCreate({ target_company_id: item.company_id }).then((res) => {
      if (res.code == 1) {
        ElMessage({ message: res.msg, type: "success" });
        getFanIndex();
      }
      if (res.code == 0) {
        ElMessage({ message: res.msg, type: "error" });
      }
    });
  }
  if (item.each == 1) {
    FanDelete({ id: item.id }).then((res) => {
      if (res.code == 1) {
        ElMessage({ message: res.msg, type: "success" });
        getFanIndex();
      }
      if (res.code == 0) {
        ElMessage({ message: res.msg, type: "error" });
      }
    });
  }
};
</script>

<style lang="stylus" scoped>
.my-fans {
  .container {
    height: calc(100vh - 204px);
  }

  .no-fans {
    margin-top: 200px;
  }
}
</style>
  